package com.example.demo.mapper;

import com.example.demo.entity.User;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface UserMapper {
    // 插入数据
    @Update("INSERT INTO `user`( `name`, `address`, `age`, `sex`, `phone`) VALUES ( #{name}, #{address}, #{age}, #{sex}, #{phone} );")
    @Transactional
    void save(User user);

    // 更新
    @Update("Update user set name=#{name}, address=#{address}, age=#{age}, sex=#{sex}, phone=#{phone} where id=#{id}")
    @Transactional
    void updateById(User user);

    //删除
    @Update("delete from user where id=#{id}")
    @Transactional
    void deleteById(Long id);

    @Select("select * from user where id=#{id}")
    User getDetail(Long id);

    List<User> findByPage(Integer offset, Integer pageSize, String name);

    @Select("select Count(id) from user")
    Integer countUser();
}
